<!--
 * @Description: 邀请列表
 * @Author: liyujie
 * @Date: 2021/07/19
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/07/19
-->
<template>
    <section class="wrapper">
        <div class="content-wrapper">
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        发起邀请用户
                    </p>
                    <el-input
                        placeholder="请输入用户编号/手机号"
                        v-model="filterData.invite_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 260px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        被邀请注册用户信息
                    </p>
                    <el-input
                        placeholder="请输入用户编号/手机号"
                        v-model="filterData.invited_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 260px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        校园精英等级
                    </p>
                    <el-select
                        placeholder="全部"
                        v-model="filterData.agent_level"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            label="全部"
                            :value="99"
                        />
                        <el-option
                            v-for="item in 6"
                            :key="item"
                            :label="`E${item - 1}`"
                            :value="item - 1"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        学生认证状态
                    </p>
                    <el-select
                        placeholder="全部"
                        v-model="filterData.verify_status"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        发放方式
                    </p>
                    <el-select
                        placeholder="全部"
                        v-model="filterData.auto_award"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in awardTypeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        发放状态
                    </p>
                    <el-select
                        placeholder="全部"
                        v-model="filterData.award_status"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in awardStatusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        黑名单用户
                    </p>
                    <el-select
                        placeholder="全部"
                        v-model="filterData.is_block"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            label="全部"
                            :value="99"
                        />
                        <el-option
                            label="是"
                            :value="1"
                        />
                        <el-option
                            label="否"
                            :value="0"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        拉新渠道
                    </p>
                    <el-select
                        placeholder="全部"
                        v-model="filterData.task_category"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            label="全部"
                            :value="99"
                        />
                        <el-option
                            label="邀请有礼"
                            :value="101"
                        />
                        <el-option
                            label="邀请PK赛"
                            :value="104"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        注册时间
                    </p>
                    <el-date-picker
                        v-model="registerDateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 360px"
                        value-format="timestamp"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        认证通过时间
                    </p>
                    <el-date-picker
                        v-model="passDateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 360px"
                        value-format="timestamp"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        奖励到账时间
                    </p>
                    <el-date-picker
                        v-model="awardDateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 360px"
                        value-format="timestamp"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        class="query-button"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                    <el-button
                        type="text"
                        @click="handleReset()"
                    >
                        重置
                    </el-button>
                </div>
            </div>
            <!--筛选-->
            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="table"
                    class="data-table"
                    :cell-style="{height: '40px'}"
                    v-loading="tableLoading"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="60"
                        type="index"
                        fixed="left"
                    />
                    <el-table-column
                        label="发起邀请用户"
                        width="200"
                        fixed="left"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-title">{{ scope.row.true_name ? scope.row.true_name : '--' }}</div>
                            <div class="cell-tips">手机号：{{ scope.row.phone }}</div>
                            <div class="cell-tips">用户ID：{{ scope.row.student_no }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="agent_level"
                        label="校园精英等级"
                        align="center"
                        width="120"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            E{{ scope.row.agent_level }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="被邀请注册用户"
                        width="200"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-title">{{ scope.row.invited_true_name ? scope.row.invited_true_name : '--' }}</div>
                            <div class="cell-tips">手机号：{{ scope.row.invited_phone }}</div>
                            <div class="cell-tips">用户ID：{{ scope.row.invited_student_no }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="注册时间"
                        align="left"
                        width="150"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.register_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="学生认证状态"
                        align="center"
                        width="150"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="status-wrapper">
                                <div
                                    class="status-dot"
                                    :class="['status-dot', scope.row.verify_status === 1 ? 'success' : scope.row.verify_status === 2 ? 'warning' : scope.row.verify_status === 0 ? 'danger' : 'normal']"
                                />
                                <div>{{ scope.row.verify_status | statusFilter }}</div>
                                <el-button
                                    type="text"
                                    v-if="scope.row.verify_status !== 0"
                                    @click="handleRoute('studentVerifyList', {
                                        student_no: scope.row.invited_student_no,
                                    })"
                                >
                                    (查看)
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="拉新渠道"
                        align="center"
                        width="150"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div v-if="scope.row.task_category === 101">邀请有礼</div>
                            <div v-if="scope.row.task_category === 104">邀请PK赛</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="认证通过时间"
                        align="left"
                        width="150"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.verify_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="发放方式"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.auto_award ? '自动打款' : '手动打款' }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="award_money"
                        label="奖励金额(元)"
                        align="center"
                        width="110"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <span style="color: #FF8E39">{{ scope.row.award_money }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="发放状态"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="status-wrapper">
                                <div
                                    class="status-dot"
                                    :class="['status-dot', scope.row.award_status === 1 ? 'warning' : scope.row.award_status === 0 ? 'normal' : 'success']"
                                />
                                {{ scope.row.award_status === 1 ? '待发放' : scope.row.award_status === 0 ? '未完成' : '已发放' }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="奖励到账时间"
                        align="left"
                        width="150"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.award_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="is_block"
                        label="黑名单用户"
                        align="center"
                        width="110"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <span :style="{color: scope.row.is_block ? '#F95B56' : ''}">{{ scope.row.is_block ? '是' : '否' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        align="left"
                        width="100"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    size="medium"
                                    :disabled="scope.row.auto_award === 1 || scope.row.award_status === 2 || scope.row.verify_status === 0 || scope.row.task_category === 104"
                                    @click="grantAward(scope.row)"
                                >
                                    发放奖励
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->
            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
    </section>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'InviteFriendsList',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                // 邀请者姓名/手机/ID
                invite_keyword: '',
                // 邀请学生编号
                invite_student_no: '',
                // 受邀请者姓名/手机/ID
                invited_keyword: '',
                agent_level: 99,
                // 班级认证状态 99：全部0未认证,1已认证2待审核,-1:审核不通过
                verify_status: 99,
                // 奖励发放类型99:全部,0:手动,1:自动
                auto_award: 99,
                // 奖励发放状态99:全部,0:未完成,1:待发放,2:已发放
                award_status: 99,
                // 黑名单
                is_block: 99,
                task_category: 99,
                // 申请开始时间
                apply_start_time: '',
                // 申请结束时间
                apply_end_time: '',
                // 认证通过开始时间
                verify_start_time: '',
                // 认证通过结束时间
                verify_end_time: '',
                // 奖励开始时间
                award_start_time: '',
                // 奖励结束时间
                award_end_time: '',
            },
            dataTimeRange: [],
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            registerDateTimeRange: null,
            passDateTimeRange: null,
            awardDateTimeRange: null,
            statusList: [
                {label: '全部', value: 99},
                {label: '未认证', value: 0},
                {label: '已认证', value: 1},
                {label: '待审核', value: 2},
                {label: '审核不通过', value: -1},
            ],
            typeList: [
                {label: '全部', value: 99},
                {label: '创建班级', value: 1},
                {label: '直接认证', value: 2},
            ],
            awardTypeList: [
                {label: '全部', value: 99},
                {label: '自动打款', value: 1},
                {label: '手动打款', value: 0},
            ],
            awardStatusList: [
                {label: '全部', value: 99},
                {label: '未完成', value: 0},
                {label: '待发放', value: 1},
                {label: '已发放', value: 2},
            ],
            authResult: {}
        };
    },
    computed: {},
    filters: {
        statusFilter(val) {
            switch (val) {
                case 0:
                    return '未认证';
                case 1:
                    return '已认证';
                case 2:
                    return '待审核';
                case -1:
                    return '审核不通过';
                default:
                    return '--';
            }
        }
    },
    watch: {},
    mounted() {
        let query = this.$route.query;

        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '邀请好友'}, {title: '邀请列表'}]);
        this.authResult = this.$route.meta.authResult;
        this.filterData.verify_status = query.verify_status ? Number(query.verify_status) : 99;
        this.filterData.invite_keyword = query.invite_student_no ? query.invite_student_no : '';
        this.filterData.award_status = query.award_status ? Number(query.award_status) : 99;
        this.awardDateTimeRange = query.start_time ? [Number(query.start_time), Number(query.end_time)] : null;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            params.register_start_time = this.registerDateTimeRange ? this.registerDateTimeRange[0] / 1000 : '';
            params.register_end_time = this.registerDateTimeRange ? this.registerDateTimeRange[1] / 1000 : '';
            params.verify_start_time = this.passDateTimeRange ? this.passDateTimeRange[0] / 1000 : '';
            params.verify_end_time = this.passDateTimeRange ? this.passDateTimeRange[1] / 1000 : '';
            params.award_start_time = this.awardDateTimeRange ? this.awardDateTimeRange[0] / 1000 : '';
            params.award_end_time = this.awardDateTimeRange ? this.awardDateTimeRange[1] / 1000 : '';
            this.$post('/student/task_stuagent_extra_student_invite%5Cget_invite_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 重置筛选条件
         */
        handleReset() {
            this.filterData = {
                invite_keyword: '',
                invite_student_no: '',
                invited_keyword: '',
                agent_level: 99,
                verify_status: 99,
                auto_award: 99,
                award_status: 99,
                is_block: 99,
                apply_start_time: '',
                apply_end_time: '',
                verify_start_time: '',
                verify_end_time: '',
                award_start_time: '',
                award_end_time: '',
            };
            this.registerDateTimeRange = null;
            this.passDateTimeRange = null;
            this.awardDateTimeRange = null;
            this.getTableData(1);
        },

        /**
         * 发放奖励
         * @param row
         */
        grantAward(row) {
            this.$zdConfirm(`${row.is_block ? '该用户为黑名单用户，是否确认发放该笔奖励?' : '是否确认发放该笔奖励?'}`, '温馨提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/task_stuagent_extra_student_invite%5Caudit', {invite_no: row.invite_no}, res => {
                    if (res.code === 1) {
                        this.$notify({
                            title: '提示',
                            message: '操作成功',
                            type: 'success'
                        });
                        this.getTableData();
                    } else {
                        this.$notify({
                            title: '提示',
                            message: res.msg,
                            type: 'warning'
                        });
                    }
                });
            }).catch(() => {});
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    flex: 1;
    width: 100%;

    .content-wrapper {
        display: flex;
        height: 100%;
        flex-direction: column;
        position: relative;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;
            margin-top: 12px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
                .query-button  {
                    width: 84px;
                    height: 36px;
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #1890FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #1890FF;
                    margin-right: 12px;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
            .cell-title {
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-bottom: 12px;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 2;
            }
            .cell-content {
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 3;
            }
            .cell-tips {
                color: #999;
            }
        }
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }
        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }

        /* 分页 */
        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-dialog__body {
        padding: 0;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
}
</style>
